﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;

public partial class AdminCMS_tab_Advertisement_List : System.Web.UI.Page
{
    #region 参数
    [RequestQuery.Query(QueryKey = "zonetype")]
    public int ZoneType = 0;    //版位类型
    [RequestQuery.Query(QueryKey = "adtype")]
    public int ADType = 0;     //广告类型
    [RequestQuery.Query(QueryKey = "keyword")]
    public string keyword = string.Empty;  //关键词
    [RequestQuery.Query(QueryKey = "isactive")]
    public bool IsActive = false;  //是否活动
    #endregion

    protected void Page_Load(object sender, EventArgs e)
    {
        RequestQuery.SetQueryValues();

        if (!IsPostBack)
        {
            ddl_ADType.SelectedValue = ADType.ToString();
            ddl_ZoneType.SelectedValue = ZoneType.ToString();
            txt_keyword.Text = keyword;
            ddl_IsActive.SelectedIndex = Convert.ToInt32(IsActive);

            ProSplitPage1.DataSource = GetPagingData();  //给分页控件附值
            ProSplitPage1.AppendQuery = RequestQuery.GetQueryValues();
            repeater1.DataSource = ProSplitPage1.SplitSource(); //返回拆分结果
            repeater1.DataBind();
        }
    }

    #region 分页方法
    public DataSet GetPagingData()
    {
        StringBuilder sql = new StringBuilder();
        sql.Append(
@"SELECT a.adv_ImgUrl, a.adv_ImgHeight, a.adv_ZoneID, a.adv_PubDate, a.adv_LinkTarget, a.adv_ID, a.adv_Description, 
a.adv_Clicks, a.adv_ADType, a.adv_ADName, a.adv_ImgWidth
FROM [tab_Advertisement] a
left join tab_AdZone b
on a.adv_ZoneID = b.adz_ID
where a.adv_IsActive = ").Append(IsActive);
        /* 追加条件*/
        //版位类型
        if (ZoneType != 0)
        {
            sql.Append(" and b.adz_ZoneType = ").Append(ZoneType);
        }
        //版位类型
        if (ADType != 0)
        {
            sql.Append(" and a.adv_ADType = ").Append(ADType);
        }
        //关键字
        if (keyword != string.Empty)
        {
            sql.Append(" and a.adv_ADName like '%").Append(ADType).Append("%'");
        }

        string Primary = "adv_ID"; //主键
        string Orderby = Primary + " DESC";  //排序
        return DataEntity.Common.ExecuteSplitPage(sql.ToString(), Primary, Orderby, ProSplitPage1.MaxRows, ProSplitPage1.PageIndex);
    }
    #endregion
}
